package com.txts.road.admin.teamSys.controller;

import com.txts.base.common.domain.PageResult;
import com.txts.base.common.domain.ResponseDTO;
import com.txts.road.admin.common.annotation.Anonymous;
import com.txts.road.admin.common.annotation.Log;
import com.txts.road.admin.common.core.controller.BaseController;
import com.txts.road.admin.common.core.domain.AjaxResult;
import com.txts.road.admin.common.core.page.TableDataInfo;
import com.txts.road.admin.common.enums.BusinessType;
import com.txts.road.admin.common.utils.poi.ExcelUtil;
import com.txts.road.admin.teamSys.domain.TeamInfo;
import com.txts.road.admin.teamSys.service.ITeamInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletResponse;

import java.util.List;

/**
 * 车队信息Controller
 *
 * @author ruoyi
 * @date 2025-04-19
 */
@RestController
@RequestMapping("/TeamSys/teamInfo")
@Tag(name = "车队接口")
public class TeamInfoController extends BaseController {
    @Resource
    private ITeamInfoService teamInfoService;

    /**
     * 查询车队信息列表
     */
    //@PreAuthorize("@ss.hasPermi('TeamSys:teamInfo:list')")
    @GetMapping("/list")
    @Anonymous
    @Operation(summary = "查询车队信息列表", description = "根据条件查询车队信息列表")
    public ResponseDTO<PageResult<TeamInfo>> list(TeamInfo teamInfo) {
        startPage();
        List<TeamInfo> list = teamInfoService.selectTeamInfoList(teamInfo);
        return getDataTable(list);
    }

    /**
     * 导出车队信息列表
     */
    @PreAuthorize("@ss.hasPermi('TeamSys:teamInfo:export')")
    @Log(title = "车队信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出车队信息列表", description = "导出车队信息列表")
    public void export(HttpServletResponse response, TeamInfo teamInfo) {
        List<TeamInfo> list = teamInfoService.selectTeamInfoList(teamInfo);
        ExcelUtil<TeamInfo> util = new ExcelUtil<TeamInfo>(TeamInfo.class);
        util.exportExcel(response, list, "车队信息数据");
    }

    /**
     * 获取车队信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('TeamSys:teamInfo:query')")
    @GetMapping(value = "/{teamId}")
    @Operation(summary = "获取车队信息详细信息", description = "根据车队ID获取车队信息详细信息")
     public ResponseDTO<Object> getInfo(@PathVariable("teamId") String teamId) {
        return success(teamInfoService.selectTeamInfoByTeamId(teamId));
    }

    /**
     * 新增车队信息
     */
    @PreAuthorize("@ss.hasPermi('TeamSys:teamInfo:add')")
    @Log(title = "车队信息", businessType = BusinessType.INSERT)
    @PostMapping
    @Operation(summary = "新增车队信息", description = "新增车队信息")
    public ResponseDTO<Object>add(@RequestBody TeamInfo teamInfo) {
        return toAjax(teamInfoService.insertTeamInfo(teamInfo));
    }

    /**
     * 修改车队信息
     */
    @PreAuthorize("@ss.hasPermi('TeamSys:teamInfo:edit')")
    @Log(title = "车队信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @Operation(summary = "修改车队信息", description = "修改车队信息")
    public ResponseDTO<Object>edit(@RequestBody TeamInfo teamInfo) {
        return toAjax(teamInfoService.updateTeamInfo(teamInfo));
    }

    /**
     * 删除车队信息
     */
    @PreAuthorize("@ss.hasPermi('TeamSys:teamInfo:remove')")
    @Log(title = "车队信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{teamIds}")
    @Operation(summary = "删除车队信息", description = "删除车队信息")
    public ResponseDTO<Object>remove(@PathVariable String[] teamIds) {
        return toAjax(teamInfoService.deleteTeamInfoByTeamIds(teamIds));
    }
}
